a = int(input('введите 4-х значное число '))
if a > 9999 or a < 1000:
    print("0")
    exit()
a1=a //1000
a2=(a-a1*1000) // 100
a3=a//10 % 10
a4= a % 10
maxX=0
b=[a1,a2,a3,a4,a1 * 10 + a2,a1 * 100 + a2*10 + a3,a2*10 + a3,a2 * 100 + a3*10 + a4,a3 * 10 + a4]
for i in range(len(b)):
    count = 0
    for c in range(2, b[i] // 2 + 1):
        if (b[i] % c == 0):
            count += 1
    if (count <= 0):
        if maxX < b[i]:
            maxX = b[i]
print(maxX)